/**
 * Project: TacticaPescaditos
 * File: Dribble.java
 */
package org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.fsm.state;

import org.javahispano.javacup.modelo.Posicion;

import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.Ball;
import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.TeamPlayer;
import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.geometrics.Vector2D;
import org.javahispano.javacup.tacticas_aceptadas.Pescaditos.com.chidotronics.javacup.messages.Telegram;

/**
 * @author Carlos Alberto
 * class: Dribble
 */
public class Dribble implements State<TeamPlayer> {
	
	private String name;

	/**
	 * 
	 */
	private Dribble() {
		this.name = "Dribble";
	}

	public static final State<TeamPlayer> instance = new Dribble();

	public void enter(TeamPlayer player) {
		player.getSteering().seekOn();
		player.getTactica().setControllingPlayer(player);
		if (player.canKick()) {
			
			Vector2D pos = player.getPosition();
			Posicion destination = new Posicion(pos.x,pos.y+10);
			player.kick(destination, player.getDribblingFactor(),0 );		
			
		}
	}

	public void execute(TeamPlayer player) {
		
		if ( player.canKick()) {			
			player.getStateMachine().changeState(KickBall.instance);
			return;
		}
		
		if (player.isClosestToBall()){
			player.getStateMachine().changeState(ChaseBall.instance);
			return;
		}
		
		player.getSteering().setTarget(player.getHomePosition());
		player.getStateMachine().changeState(Wait.instance);

		
	}

	public void exit(TeamPlayer player) {
	
	}

	public boolean onMessage(TeamPlayer o, Telegram telegram) {
		return false;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.name.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.name;
	}
}
